import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nft_shop/my/page/wallet/my_record_list_page.dart';
import 'package:nft_shop/my/page/wallet/my_wallet_details.dart';
import 'package:nft_shop/net/service_repository.dart';
import 'package:nft_shop/res/constant.dart';
import 'package:nft_shop/res/global.dart';
import 'package:nft_shop/util/route_observer.dart';
import 'package:nft_shop/widgets/custom_underline_tabIndicator.dart';
import 'package:nft_shop/widgets/my_app_bar.dart';
import 'package:nft_shop/widgets/status_view.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class MyRecordPage extends StatefulWidget {
  const MyRecordPage({Key? key}) : super(key: key);

  @override
  _MyRecordPageState createState() => _MyRecordPageState();
}

class _MyRecordPageState extends State<MyRecordPage>
    with
        SingleTickerProviderStateMixin {
  TabController? _tabController;
  final PageController _pageController = PageController(initialPage: 0);

  @override
  void dispose() {
    super.dispose();
    _tabController?.dispose();
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(vsync: this, length: 3);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(48),
        child: AppBar(
          title: titleWidget(),
          leading: IconButton(
            padding: const EdgeInsets.only(right: 12, top: 12, bottom: 12),
            icon: Image.asset(
              'assets/images/ic_back_black.png',
            ),
            onPressed: () {
              Get.back();
            },
          ),
          actions: [
            Container(
              padding: const EdgeInsets.only(right: 12, top: 12, bottom: 12),
              child: SizedBox(width: 36,),
            ),
          ],
        ),
      ),
      body: Column(
        children: [
          Container(
            height: 5,
            color: Global.kTheme.colorLine,
          ),
          Expanded(
              child: PageView.builder(
            itemCount: 3,
            onPageChanged: _onPageChange,
            controller: _pageController,
            itemBuilder: (_, int index) {
              return MyRecordListPage(type: index,);
            },
          ))
        ],
      ),
    );
  }

  //标题
  Widget titleWidget() {
    return Container(
      height: 40,
      child: TabBar(
        onTap: (index) {
          if (!mounted) {
            return;
          }
          _pageController.jumpToPage(index);
        },
        isScrollable: false,
        controller: _tabController,
        labelStyle: TextStyle(
          fontSize: 14,
          fontFamily: Global.mySemiboldFont,
        ),
        unselectedLabelStyle: TextStyle(
          fontSize: 14,
        ),
        indicatorSize: TabBarIndicatorSize.label,
        unselectedLabelColor: Color(0xFF222222),
        labelColor: Color(0xFF222222),
        indicatorPadding: EdgeInsets.only(bottom: 0, left: 3, right: 3),
        indicator: CustomUnderlineTabIndicator(
            borderSide: BorderSide(
          color: Color(0xFF000000),
          width: 4,
        )),
        tabs: [
          Tab(
            text: "全部",
          ),
          Tab(
            text: "收入",
          ),
          Tab(
            text: "支出",
          ),
        ],
      ),
    );
  }



  void _onPageChange(int index) {
    _tabController?.animateTo(index);
  }
}
